<?php

namespace app\api\validate;

use think\Validate;

class WeChatMerchantValidator extends Validate
{
    protected $rule = [
        'name|真实姓名' => 'require|max:32',
        'store_name|店铺名称' => 'require|max:100',
        'mobile|手机号' => 'require|mobile|max:20',
        'merchant_name|商户名称' => 'require|max:100',
        'company_address|注册地址' => 'require|max:100',
        'business_license_number|统一社会信用代码' => 'require|max:50',
        'legal_person|法人/经营者姓名' => 'require|max:50',
        'business_start_time|成立日期' => 'require|max:20',
        'business_end_time|营业期限' => 'require|max:20',
        'business_license_copy|营业执照编码' => 'require|max:150',
        'business_license_image|营业执照图片' => 'require|max:150',
        'sales_scenes_type|营业执照图片' => 'require|max:150',
        'store_entrance_pic|线下门店内部照片' => 'require|max:255',
        'store_entrance_pic_code|线下门店内部照片编码' => 'require|max:255',
        'indoor_pic|线下场所门头照片' => 'require|max:255',
        'indoor_pic_code|线下场所门头照片编码' => 'require|max:255',
        'id_card_national_image|法人身份证反面照片' => 'require|max:150',
        'id_card_national|法人身份证反面照片编码' => 'require|max:150',
        'id_card_image|法人身份证正面照片' => 'require|max:150',
        'id_card_copy|法人身份证正面照片编码' => 'require|max:150',
        'id_card_name|法人姓名' => 'require|max:50',
        'id_card_valid_time_begin|法人身份证开始时间' => 'require|max:30',
        'id_card_valid_time|法人身份证到期时间' => 'require|max:30',
        'id_card_number|法人身份证编号' => 'require|idCard|max:100',
        'id_card_address|法人身份证居住地址' => 'require|max:255',
        'account_number|银行卡号' => 'require|max:30',
        'bank_name|开户银行全称' => 'require|max:30',
        'bank_address|开户银行省市区' => 'require|max:200',
        'bank_address_code|开户银行省市区编码' => 'require|max:30',
        'industry_id|行业选择' => 'require|max:11',
        'email|邮箱' => 'require|email|max:50',
        'biz_store_address|线下场所详细地址' => 'require|max:255',
        'biz_address_code|线下场所省市区编码' => 'require|max:255',
        'biz_address_name|线下场所省市区' => 'require|max:255',
        'contact_name|管理员姓名' => 'require|max:255',
        'contact_id_card_number|管理员证件号' => 'require|idCard|max:255',
        'contact_id_doc_period_begin|管理员证件有效期开始时间' => 'require|max:50',
        'contact_id_doc_period_end|管理员证件有效期结束时间' => 'require|max:50',
        'bank_account_type|账户类型' => 'require|max:20',
        'contact_id_doc_image_path|管理员身份证正面照片' => 'require|max:150',
        'contact_id_doc_copy|管理员身份证正面照片编码' => 'require|max:150',
        'contact_id_doc_back_path|管理员身份证反面照片' => 'require|max:150',
        'contact_id_doc_copy_back|管理员身份证反面照片编码' => 'require|max:150',
        'business_authorization_letter_path|授权函照片' => 'require|max:150',
        'business_authorization_letter|授权函照片编码' => 'require|max:150',
        'contact_type|管理员类型' => 'require|max:10',
        'type|企业类型' => 'require|max:10',
        'account_name|开户名' => 'require|max:30',
        'account_bank|开户银行' => 'require|max:30',
        'id_doc_type|法人证件类型' => 'require|max:255',
        'contact_id_doc_type|管理员证件类型' => 'require|max:150'
    ];

    protected $scene = [
        'add' => ['name', 'store_name', 'mobile', 'merchant_name', 'company_address', 'legal_person', 'business_start_time', 'business_end_time', 'business_license_copy', 'business_license_image', 'sales_scenes_type', 'id_card_national_image', 'id_card_national', 'id_card_image', 'id_card_copy', 'id_card_name', 'id_card_valid_time_begin', 'id_card_valid_time', 'id_card_number', 'id_card_address', 'account_number', 'industry_id', 'email', 'biz_store_address', 'biz_address_code', 'biz_address_name', 'bank_account_type', 'contact_type', 'type', 'account_name', 'account_bank', 'id_doc_type', 'business_license_number'],
        'contact' => ['contact_name', 'contact_id_card_number', 'contact_id_doc_period_begin', 'contact_id_doc_period_end', 'contact_id_doc_image_path', 'contact_id_doc_copy', 'contact_id_doc_back_path', 'contact_id_doc_copy_back', 'business_authorization_letter_path', 'business_authorization_letter'],
        'account_bank' => ['bank_name', 'bank_address', 'bank_address_code'],
        'sales_scenes' => ['store_entrance_pic', 'store_entrance_pic_code', 'indoor_pic', 'indoor_pic_code']
    ];

    public function add(array $params)
    {
        if (!$this->scene('add')->check($params)) {
            return false;
        }

        // 判断管理员类型:66为管理员，管理员需要验证管理员信息和授权函,65为法人
        if ($params['contact_type'] == 66) {
            if (!$this->scene('contact')->check($params)) {
                return false;
            }
        }

        // account_bank 为其他银行是，验证支行信息
        if ($params['account_bank'] == '其他银行') {
            if (!$this->scene('account_bank')->check($params)) {
                return false;
            }
        }
        if ($params['sales_scenes_type'] == 'SALES_SCENES_STORE') {
            if (!$this->scene('sales_scenes')->check($params)) {
                return false;
            }
        }
        return true;
    }
}
